import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';

class DataManagerDB{
  static final String DBTabName = "manager.db";

  static final String imageManagerTableName = 'imageManagerTableName';
  static final String millisecondTimeStr = "millisecondTimeStr";
  static final String netPath = 'netPath';
  static final String imagePath = 'imagePath';
  static final String imageName = 'imageName';
  static final String imageId = 'imageId';

  static final DataManagerDB _instance = new DataManagerDB.internal();
  factory DataManagerDB() => _instance;
  DataManagerDB.internal();

  static Database? database;

  /**
   * 初始化数据库
   */
  Future<Database?> getDB() async {
    if (database == null){
      String databasesPath = await getDatabasesPath();
      String path = join(databasesPath, DBTabName);
      print("save path:${path}");
      var createTABStr = "CREATE TABLE ${imageManagerTableName} (${imageId} TEXT UNIQUE ON CONFLICT REPLACE, ${netPath} TEXT,"
          " ${imagePath} TEXT, ${millisecondTimeStr} TEXT,${imageName} TEXT,PRIMARY KEY (${imageId}) );";
//      print("createTABStr:${createTABStr}");
      database = await openDatabase(path, version: 1,
          onCreate: (Database db, int version) async {
            await db.execute(createTABStr);
//            await db.execute(
//                'CREATE TABLE ${manhuaimageTableNmae} (${manhuaid} TEXT UNIQUE ON CONFLICT REPLACE, ${manhuaname} TEXT,'
//                    ' ${manhuatitle} TEXT, ${manhuapage} TEXT,${manhualistjson} TEXT,PRIMARY KEY (${manhuaid}))');
          });
    }
    return database;
  }






}
